package com.wyp168.leetcode;

/**
 * @ClassName RemoveElement
 * @Description TODO
 * @Author wyp168
 * @Date 2022/7/18 19:35
 */
public class RemoveElement {
    public static void main(String[] args) {

        int[] integers = {0,1,2,2,3,0,4,2};
        System.out.println(removeElement(integers, 2));


    }

    public static int removeElement(int[] nums, int val) {
        int lIndex = 0;
        int quickIndex = 0;
        int length = 0;
        while (quickIndex < nums.length) {
            if (nums[quickIndex] == val) {
                quickIndex ++;
                continue;
            } else {
                nums[lIndex] = nums[quickIndex];
                lIndex ++;
                quickIndex ++;
                length ++;
            }
        }
        return length;
    }
}
